#include "ClientSocket.h"
#include <iostream>
ClientSocket::ClientSocket()
{
}

ClientSocket::~ClientSocket()
{
	//SDLNet_TCP_DelSocket(m_socketSet, m_socket);
	//SDLNet_TCP_Close(m_socket);
	//SDLNet_FreeSocketSet(m_socketSet);
}

bool ClientSocket::Open(const std::string& hostname, int port)
{
	SDLNet_ResolveHost(&m_ip, hostname.c_str(), port);

	if (m_ip.host == INADDR_NONE)
	{
		// can't find address
		std::cout << "failed to find server address" << std::endl;
		return false;
	}
	std::cout << "found server" << std::endl;

	m_socket = SDLNet_TCP_Open(&m_ip);
	if (!m_socket)
	{
		std::cout << "failed to open socket on port: " << port << std::endl;
		return false;
	}
	std::cout << "socket opened on port: " << port << std::endl;

	SDLNet_TCP_AddSocket(m_socketSet, m_socket);

	std::cout << "connected" << std::endl;

	return true;
}

void ClientSocket::SetSocket(const TCPsocket& s)
{
	m_socket = s;
}

void ClientSocket::SetID(int i)
{
	m_id = i;
}

int ClientSocket::GetID() const
{
	return m_id;
}

const D3DXVECTOR3& ClientSocket::GetPos() const
{
	return m_info.pos;
}

void ClientSocket::SetPos(const D3DXVECTOR3& pos)
{
	m_info.pos = pos;
}

const D3DXVECTOR3& ClientSocket::GetVel() const
{
	return m_info.vel;
}

void ClientSocket::SetVel(const D3DXVECTOR3& vel)
{
	m_info.vel = vel;
}